<template>
  <div id="sign-in">
    <h2>用户注册</h2>
    <el-row style="margin-bottom:20px">
      <el-radio-group v-model="form.size">
        <el-radio :label="'medium'">默认</el-radio>
        <el-radio :label="'small'">small</el-radio>
        <el-radio :label="'mini'">mini</el-radio>
      </el-radio-group>
    </el-row>

    <el-form :model="form" :size="form.size" :rules="formRules" ref="form" :inline="true">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="性别" >
        <el-radio v-model="form.sex" label='1'>男</el-radio>
        <el-radio v-model="form.sex" label='0'>女</el-radio>
      </el-form-item>
      <el-form-item label="出生日期">
        <el-date-picker v-model="form.birthDate" type="date" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>

      <div>
        <el-form-item>
          <el-button type="primary" @click="submitForm('form')">注册</el-button>
          <el-button @click="resetForm('form')">重置</el-button>
        </el-form-item>
      </div>
    </el-form>

    <!-- 信息确定对话框 -->
    <div ref="formDialogBox" style="display: block">
      <p>用户名:{{ form.username }}</p>
      <p>性别: {{ form.sex === '1' ? '男' : '女' }}</p>
      <p>出生日期:{{ form.birthDate }}</p>
    </div>

  </div>
</template>

<script>
export default {
  name: 'sign-in',
  data () {
    return {
      form: {
        username: '',
        size: 'medium',
        sex: '1',
        birthDate: ''
      },
      formRules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.confirmFormDialog()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    confirmFormDialog () {
      this.$confirm(this.$refs.formDialogBox.innerHTML, '确认信息', {
        distinguishCancelAndClose: true,
        dangerouslyUseHTMLString: true,   // 确定是HTML字符串
        confirmButtonText: '确定注册',
        cancelButtonText: '取消'
      })
      .then(() => {
        this.$message({
          type: 'info',
          message: '注册成功'
        })
      })
      .catch(action => {
        // this.$message({
        //   type: 'info',
        //   message: action === 'cancel'
        //     ? '放弃保存并离开页面'
        //     : '停留在当前页面'
        // })
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
